package cglib;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class CglibTimeAspect implements MethodInterceptor {
   private  Object target;
   public CglibTimeAspect(Object target){
       this.target = target;
   }
    @Override
    public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
//        获取当前时间
        long t1 = System.currentTimeMillis();
       Object returnVal =  method.invoke(target,args);
//        获取当前时间
        long t2 = System.currentTimeMillis();
        System.out.println("耗时："+(t2-t1));
        return returnVal;
    }
}
